import jieba
import util.file as RF
import util.IO as RI

class Factory:
    def __init__(self,path,gap):
        self.__caseData=[]
        with open(path,'r',encoding='utf-8') as f:
            data=f.read().split('\n')
            for line in data:
                self.__caseData.append(line.split(gap))
        self.__wordVector=[]
        self.__sampleSize=self.__caseData.__len__()
    def divide(self):
        for i in range(self.__sampleSize):
            case=self.__caseData[i][1]
            caseCut = ""
            add = True
            for s in case:
                if s == "<":
                    add = False
                if s == "&":
                    add = False
                if add:
                    caseCut += s
                if s == ">":
                    add = True
                if s == ";":
                    add = True
            segList = jieba.lcut(caseCut)
            segList.insert(0,self.__caseData[i][0])
            self.__wordVector.append(segList)
            RI.progressBar(i,self.__sampleSize)
    def saveVector(self,path):
        RF.write(path,self.__wordVector,gap='\t')
if __name__ == '__main__':
    factory=Factory(RF.getRootPath()+'data\dataBase\case.csv','\t')
    factory.divide()
    factory.saveVector(RF.getRootPath()+'data\dataBase\\vector.csv')
